<template>
  <div class="leftUploadSearch">
    <div class="l-image-upload">
      <div v-if="uploadImgList.length > 0" class="l-i-u-bg">
        <div v-for="(item, index) in uploadImgList" :key="index" class="l-u-img-box">
          <img :src="item.file.src" class="l-u-img" />
          <div class="del-img">
            <i class="el-icon-close" @click="delImgClick(index)"></i>
          </div>
        </div>
      </div>
      <div v-if="uploadImgList.length !== 3" class="l-upload-btn" @click="fileClick">
        <i class="el-icon-plus"></i>
      </div>
      <input @change="fileChange($event)" type="file" id="upload_file" multiple style="display: none" />
    </div>
    <div class="l-sel-time">
      <el-date-picker v-model="selTime" type="datetime" placeholder="选择时间" size="small" style="width: 100%">
      </el-date-picker>
    </div>
    <div class="l-days-box">
      <div class="common-day" :class="isSelDay ? 'sel-Bg' : 'defaut-bg'" @click="selDayClick(3)">近3天</div>
      <div class="common-day" :class="isSelDay1 ? 'sel-Bg' : 'defaut-bg'" @click="selDayClick(7)">近7天</div>
      <div class="common-day" :class="isSelDay2 ? 'sel-Bg' : 'defaut-bg'" @click="selDayClick(30)">近30天</div>
    </div>
    <div class="comparison_box">
      <span>对比阈值</span>
      <div class="block">
        <el-slider class="slider" v-model="threshold" input-size="mini"></el-slider>
        <el-input-number
          size="mini"
          class="input-number"
          v-model="threshold"
          controls-position="right"
          :min="0"
          :max="100"
        ></el-input-number>
      </div>
    </div>
    <div class="l-button-box">
      <div class="common-btn" @click="resetClick">
        <SvgIcon icon-class="reset" style="width: 19.5px; height: 19.5px" />
        <div class="common-btn-label">重置</div>
      </div>
      <div class="common-btn" @click="searchClick">
        <SvgIcon icon-class="search" style="width: 19.5px; height: 19.5px" />
        <div class="common-btn-label">搜索</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "commonArchiveImage",
  props: {
    commonTitle: {
      type: String,
      default: "搜索人出行记录"
    },
    recordList: {
      type: Array,
      default: () => []
    }
  },
  components: {},
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  data() {
    return {
      selTime: "", // 时间
      threshold: 60, // 对比阈值
      isSelDay: true,
      isSelDay1: false,
      isSelDay2: false,
      uploadImgList: []
    }
  },
  methods: {
    selDayClick(num) {
      if (num == 3) {
        this.isSelDay = true
        this.isSelDay1 = false
        this.isSelDay2 = false
      } else if (num == 7) {
        this.isSelDay = false
        this.isSelDay1 = true
        this.isSelDay2 = false
      } else {
        this.isSelDay = false
        this.isSelDay1 = false
        this.isSelDay2 = true
      }
    },
    // 上传图片相关方法
    fileClick() {
      document.getElementById("upload_file").click()
    },
    fileChange(el) {
      if (!el.target.files[0].size) return
      if (el.target.files.length > 3) {
        console.log(el.target.files.length, "dddddd")
        this.$message.error("最多只能上传3张图片")
      } else {
        this.fileList(el.target.files)
        el.target.value = ""
      }
    },
    fileList(files) {
      console.log(files)
      for (let i = 0; i < files.length; i++) {
        this.fileAdd(files[i])
      }
    },
    fileAdd(file) {
      this.size = this.size + file.size //总大小
      let reader = new FileReader()
      reader.vue = this
      reader.readAsDataURL(file)
      reader.onload = function () {
        file.src = this.result
        console.log(file)
        this.vue.uploadImgList.push({
          file
        })
        console.log(this.vue.uploadImgList)
      }
    },
    // 删除图片
    delImgClick(index) {
      this.uploadImgList.splice(index, 1)
    },
    // 重置点击
    resetClick() {
      this.$emit("resetClick", this.uploadImgList)
    },
    // 搜索点击
    searchClick() {
      this.$emit("searchClick", this.uploadImgList)
    }
  }
}
</script>

<style scoped lang="scss">
.leftUploadSearch {
  // margin-top: -20px;
  width: 100%;
  height: 100%;
  background-image: url("@/assets/images/investigateBusiness/analysis-left-bg.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  position: relative;
  padding-top: 1px;
  .l-image-upload {
    margin: 40px 25px 0;
    width: 268px;
    height: 126px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    box-sizing: border-box;
    border: 1px dashed rgba(255, 255, 255, 0.6);
    display: flex;
    .l-i-u-bg {
      display: flex;
      .l-u-img-box {
        width: 60px;
        height: 60px;
        border-radius: 5px;
        // background: rgba(3, 3, 3, 0.5);
        margin-top: 14px;
        margin-left: 10px;
        position: relative;
        .l-u-img {
          width: 60px;
          height: 60px;
          border-radius: 5px;
        }
        .del-img {
          display: none;
        }
        &:hover {
          .del-img {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 60px;
            height: 60px;
            border-radius: 5px;
            background: rgba(3, 3, 3, 0.5);
            i {
              position: absolute;
              top: 2px;
              right: 2px;
              font-size: 14px;
            }
          }
        }
      }
    }

    .l-upload-btn {
      width: 60px;
      height: 60px;
      line-height: 60px;
      text-align: center;
      border-radius: 5px;
      background: rgba(255, 255, 255, 0.05);
      box-sizing: border-box;
      border: 1px dashed rgba(255, 255, 255, 0.6);
      font-size: 20px;
      margin-top: 14px;
      margin-left: 10px;
      cursor: pointer;
    }
  }
  .l-sel-time {
    margin: 20px 25px 0;
    width: 268px;
  }
  .l-days-box {
    margin: 20px 25px 0;
    display: flex;
    .common-day {
      width: 88px;
      height: 28px;
      line-height: 28px;
      text-align: center;
      border-radius: 3px;
      background: rgba(255, 255, 255, 0.2);
      font-family: "Microsoft YaHei";
      font-size: 14px;
      color: rgba(255, 255, 255, 0.9);
      margin-right: 5px;
      &:last-child {
        margin-right: 0px;
      }
      cursor: pointer;
    }
    .sel-Bg {
      background: #0e9cff;
    }
    .defaut-bg {
      background: rgba(255, 255, 255, 0.2);
    }
  }
  .comparison_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 25px 0;
    .block {
      width: calc(100% - 70px);
      margin-right: 5px;
      display: flex;
      align-items: center;
      .slider {
        width: 50%;
        float: left;
        margin-right: 5px;
      }
      .input-number {
        width: calc(50% - 5px);
        float: left; // padding: 0;
      }
    }
  }
  .l-button-box {
    position: absolute;
    bottom: 40px;
    left: 20px;
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    // justify-content: center;
    .common-btn {
      margin-left: 26px;
      width: 100px;
      height: 40px;
      border-radius: 60px;
      opacity: 1;
      background: rgba(10, 26, 52, 0.6);
      border: 1px solid rgba(89, 175, 249, 0.7049);
      box-shadow: inset 0px 0px 5px 0.5px rgba(3, 251, 255, 0.6513);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      .common-btn-label {
        margin-left: 10px;
        font-family: "SourceHanSans";
        font-size: 16px;
        font-weight: normal;
        line-height: 20px;
        letter-spacing: 0px;
        color: #01c2ff;
      }
    }
  }
}
::v-deep {
  .l-sel-time .el-input__inner,
  .comparison_box .el-input__inner {
    background: rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: #fff;
  }
  .comparison_box .el-input-number__decrease,
  .comparison_box .el-input-number__increase {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
  }
}
</style>
